//全选、全不选、反选函数
//全选函数
//参数 id 指html里的ID范围内
function select_all(id)
{
	if(id && id != "undefined")
	{
		var objs = $(id).getElementsByTagName("input");
	}
	else
	{
		var objs = window.document.getElementsByTagName("input");
	}
	for(var i=0; i<objs.length; i++)
	{
		if(objs[i].type.toLowerCase() == "checkbox" ) objs[i].checked = true;
	}
}

//全不选函数
//参数 id 指html里的ID范围内
function select_none(id)
{
	if(id && id != "undefined")
	{
		var objs = $(id).getElementsByTagName("input");
	}
	else
	{
		var objs = window.document.getElementsByTagName("input");
	}
	for(var i=0; i<objs.length; i++)
	{
		if(objs[i].type.toLowerCase() == "checkbox" ) objs[i].checked = false;
	}
}

//反选函数
//参数 id 指html里的ID范围内
function select_anti(id)
{
	if(id && id != "undefined")
	{
		var objs = $(id).getElementsByTagName("input");
	}
	else
	{
		var objs = window.document.getElementsByTagName("input");
	}
	for(var i=0; i<objs.length; i++)
	{
		if(objs[i].type.toLowerCase() == "checkbox" )
		{
			if(objs[i].checked == true)
			{
				objs[i].checked = false;
			}
			else
			{
				objs[i].checked = true;
			}
		}
	}
}

/*取得复选框的值，并以,合并*/
function join_checkbox(id,type)
{
	//未定义类型的时候
	if(!type || type == "undefined" || (type != "all" && type != "checked" && type != "unchecked"))
	{
		type = "checked";
	}
	var idarray = new Array();//定义一个数组
	var cv = window.document.getElementsByTagName("input");
	var tt = document.getElementById(id);
	if(tt)
	{
		cv = tt.getElementsByTagName("input");
	}
	var m = 0;
	for(var i=0; i<cv.length; i++)
	{
		if(cv[i].type.toLowerCase() == "checkbox")
		{
			if(type == "all")
			{
				idarray[m] = cv[i].value;
				m++;
			}
			else if(type == "checked")
			{
				if(cv[i].checked)
				{
					idarray[m] = cv[i].value;
					m++;
				}
			}
			else if(type == "unchecked")
			{
				if(!cv[i].checked)
				{
					idarray[m] = cv[i].value;
					m++;
				}
			}
		}
	}
	var id = idarray.join(",");
	return id;
}

/*Select 选框的处理*/
function selected_true(idname,optioned)
{
	var obj = $(idname);
	for(i=0;i<obj.length;i++)
	{
		if(obj[i].value == optioned)
		{
			obj[i].selected = true;
		}
	}
}

//插入文件到当前光标处
function insert_txt(c,v)
{
	var obj=$(c);
	if(document.selection)
	{
		obj.focus();
		document.selection.createRange().text = v;
	}
	else
	{
		obj.value = obj.value.slice(0,Obj.selectionStart) + v + obj.value.slice(obj.selectionEnd,obj.value.length);
	}
}

/*鼠标移过去效果和离开时的特效*/
function over_div(v)
{
	v.className = "table1";
}
function out_div(v)
{
	v.className = "table";
}
function over_tr(v)
{
	v.className = "tr_over";
}
function out_tr(v)
{
	v.className = "tr_out";
}

/*创建ajax对象*/
function add_ajax()
{
	var xmlhttp=null;
	try
	{
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			xmlhttp=null;
		}
	}
	if(!xmlhttp && typeof XMLHttpRequest != "undefined")
	{
		xmlhttp=new XMLHttpRequest();
	}
    return xmlhttp;
}

function url_ajax(url)
{
	var randname = "rand"+Math.floor(Math.random()*10000);
	var randnum = Math.floor(Math.random()*10000);
	if(url.indexOf("?") != -1)
	{
		u_length = url.length;
		if(url.substr((u_length-1)-u_length) != "&")
		{
			url += "&"+randname+"="+randnum;
		}
		else
		{
			url += randname+"="+randnum;
		}
	}
	else
	{
		url += "?"+randname+"="+randnum;
	}
	return url;
}

/*根据url来处理ajax的信息*/
function get_ajax(url,ajax_func,ext)
{
	if(ajax_func && ajax_func != "undefined")
	{
		get_ajax_asyn(url,ajax_func,ext);
		return true;
	}
	else
	{
		return get_ajax_syn(url);
	}
}

/*异步处理*/
function get_ajax_asyn(url,func,ext)
{
	var xmlhttp = add_ajax();
	url = url_ajax(url);
	xmlhttp.onreadystatechange = function(){func(xmlhttp,ext)}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	return xmlhttp;
}

function ajax_result(xmlhttp)
{
	if(xmlhttp.readyState == 4)
	{
		var result = xmlhttp.responseText;
		if(!result) result = "false";
		return result;
	}
	else
	{
		return false;
	}
}

/*同步处理*/
function get_ajax_syn(url)
{
	var xmlhttp = add_ajax();
	url = url_ajax(url);
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	if(xmlhttp.readyState == 4)
	{
		var result = xmlhttp.responseText;
		if(!result) result = "false";
		return result;
	}
	else
	{
		alert("数据加载中...");
		return true;
	}
}
